<?php
/**
 *  无备注
 * ds
 * 2020.08.13
 */
namespace App\Models\MainDB;

use Illuminate\Database\Eloquent\Model;

class LisenceOrder extends Model{

    protected $table = 'ln_lisence_order';     //数据库内完整表名

    protected $primaryKey = 'order_id';    //主键名

    protected $fillable = [
        'order_id',
        'order_no',
        'user_id',
        'uid',
        'add_time',
        'status',
        'ulisence_id',
        'lisence_id',
        'order_num',
        'price',
        'memo',
        'rate_platform',
        'rate_sociaty',
        'update_time',
        'sociaty_id',
        'response_type',
        'response_memo',
        'unit',
        'is_auto',
        'is_comment',
        'is_settlement',
        'demand_id',
    ];
    public $timestamps = false;

    //范围查询
    public function scopeWithOnly($query, $relation, Array $columns)
    {
        return $query->with([$relation => function ($query) use ($columns){
            $query->select($columns);
        }]);
    }

    //关联资质模型
    public  function  lisence(){
        return $this->hasOne('App\Models\MainDB\Lisence','lisence_id','lisence_id');
    }
    //关联用户信息模型
    public function  user_data(){
        return $this->hasOne('App\Models\MainDB\UserData','user_id','user_id');
    }

    //关联大神信息模型
    public function u_data() {
        return $this->hasOne('App\Models\MainDB\UserData','user_id','uid');
    }

}